package com.csdn.leon.adapter;

import com.csdn.leon.activity.BlogHostActivity;
import com.csdn.leon.activity.WatchBloggerActivity;
import com.csdn.leon.base.R;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DialogAdapter extends BaseAdapter {

	private Context context;
	private String[] arry;
	private LayoutInflater inflater;

	public DialogAdapter(Context context, String[] arry) {
		this.context = context;
		this.arry = arry;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return arry.length;
	}

	@Override
	public Object getItem(int position) {
		return arry[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.dialog_item_layout, null);
			holder.text = (TextView) convertView.findViewById(R.id.textView1);
			convertView.setTag(holder);
		} else {
		}
		holder = (ViewHolder) convertView.getTag();
		holder.text.setText(arry[position]);
		holder.text.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				listener.cancleDialog();
				Intent intent = new Intent(context, BlogHostActivity.class);
				intent.putExtra("username", arry[position]);
				context.startActivity(intent);
				// Intent intent1 = new Intent(); //Itent就是我们要发送的内容
				// intent1.setAction("COM.DIALOG.SEARCH");
				// //设置你这个广播的action，只有和这个action一样的接受者才能接受者才能接收广播
				// context.sendBroadcast(intent1); //发送广播

			}
		});
		return convertView;
	}

	public class ViewHolder {
		private TextView text;
	}

	ClickedListener listener;

	public void setListener(ClickedListener listener) {
		this.listener = listener;
	}

	public interface ClickedListener {
		public void cancleDialog();
	}
}
